# -*- coding:utf-8 -*-
# @FileName  :3.selenium动作链和ifame.py
# @Time      :2024/8/15 下午12:54
# @Author    :鲁大师
import time
from selenium import webdriver

from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains

'''
-selenium处理iframe
-如果定位的标签存在于iframe标签之中，则必须使用switchto.frame(id)
-动作链(拖动):from selenium.webdriver import ActionChains
-实例化一个动作链对象:action=ActionChains(bro)
click and hold(div):长按且点击操作
move by offset(x,y)
perform()让动作链立即执行
-
action.release()释放动作链对象
'''

bro = webdriver.Edge()
url = 'https://www.runoob.com/try/try.php?filename=jqueryui-api-droppable'
bro.get(url=url)

# 切换浏览器标签定位的作用域
bro.switch_to.frame('iframeResult')
div = bro.find_element(By.ID, 'draggable')

# 动作链
action = ActionChains(bro)
action.click_and_hold(div)
for i in range(15):
    # perform()表示立即执行动作链
    # move_by_offset(x,y)  x:水平方向  y:垂直方向
    action.move_by_offset(17, 0).perform()
    time.sleep(0.1)
# 释放动作链
action.release()
print(div)
